package com.zzyl.controller;

import com.github.pagehelper.PageInfo;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDTO;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanDetailVO;
import com.zzyl.vo.NursingPlanVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@RequiredArgsConstructor
@Api(tags = "护理计划管理")
@Slf4j
public class NursingPlanController extends BaseController{

    private final NursingPlanService nursingPlanService;

    @GetMapping
    @ApiOperation("查询全部护理计划")
    public ResponseResult<List<NursingPlanVO>> getAllNursingPlan() {
        List<NursingPlanVO> allNursingPlan = nursingPlanService.getAllNursingPlan();
        return success(allNursingPlan);
    }

    @GetMapping("/search")
    @ApiOperation("条件分页查询护理计划")
    public ResponseResult<PageInfo<NursingPlanVO>> searchNursingPlan(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Integer status,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<NursingPlanVO> page = nursingPlanService.searchNursingPlan(name, status, pageNum, pageSize);
        return success(page);
    }

    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult add(@RequestBody NursingPlanDTO nursingPlanDTO){
        log.info("新增护理计划：{}",nursingPlanDTO);
        nursingPlanService.add(nursingPlanDTO);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理计划")
    public ResponseResult delete(@PathVariable Long id){
        nursingPlanService.deleteById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用护理计划")
    public ResponseResult startAndStop(@PathVariable Long id, @PathVariable Integer status){
        log.info("更改当前id：{}的状态status为：{}",id,status);
        nursingPlanService.startAndStop(id, status);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult<NursingPlanDetailVO> getPlanById(@PathVariable Integer id){
        NursingPlanDetailVO nursingPlanDetailVO =  nursingPlanService.getPlanDetailById(id);
        return success(nursingPlanDetailVO);
    }

    @PutMapping("/{id}")
    public ResponseResult update(@PathVariable Integer id, @RequestBody NursingPlanDTO nursingPlanDTO){
        nursingPlanService.update(id,nursingPlanDTO);
        return success();
    }
}
